package E2013;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

class student{
    // 声明变量
    String name;
    int no;
    double score;
    // 封装有参构造方法
    public student(int no,String name, double score) {
        this.no = no;
        this.name = name;
        this.score = score;

    }
    // 重写toString方法
    @Override
    public String toString() {
        return  no+"\t"+name +"\t"+ score;
    }
}
public class e05 {
    public static void main(String[] args) {
        // 创建HashTable
        Hashtable<Integer,student> hashtable = new Hashtable<>();
        // 添加数据
        hashtable.put(19412,new student(19412,"jack",96.0));
        hashtable.put(19411,new student(19411,"lucy",98.0));
        hashtable.put(19416,new student(19416,"toam",94.5));
        hashtable.put(19420,new student(19420,"jimn",93.0));
        hashtable.put(19433,new student(19433,"flink",88.5));
        System.out.println("当前共有"+hashtable.size()+"个学生。");
        System.out.println("------------学生信息-------------");
        // 获取键值集合
        Set set = hashtable.keySet();
        // 通过键值集合获取迭代器
        Iterator iterator = set.iterator();
        // 遍历
        while (iterator.hasNext()){
            Object key = iterator.next();      // 获取键值
            Object value = hashtable.get(key); // 通过键获取对应value
            System.out.println(value);
        }
        Scanner input = new Scanner(System.in);
        System.out.println("请输入要查找的学生学号：");
        int select = input.nextInt();
        if (hashtable.containsKey(select)){
            System.out.println(hashtable.get(select));
        }else {
            System.out.println("对不起没有该学生！");
        }
    }
}
